<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>随机数生成工具</title>
    <link rel="stylesheet" href="../../bootstrap/bootstrap.min.css">
</head>
<body>
    <div class="container mt-5">
        <h1 class="mb-4">随机数生成工具</h1>
        <form>
            <div class="form-group mb-3">
                <label for="num">要生成的随机数个数：</label>
                <input type="number" class="form-control" id="num" value="10" min="1">
            </div>
            <div class="form-group mb-3">
                <label for="rangeMin">随机数范围（最小值）：</label>
                <input type="number" class="form-control" id="rangeMin" value="1" min="-999999" max="999999">
            </div>
            <div class="form-group mb-3">
                <label for="rangeMax">随机数范围（最大值）：</label>
                <input type="number" class="form-control" id="rangeMax" value="100" min="-999999" max="999999">
            </div>
            <button type="button" class="btn btn-primary" onclick="generate()">生成</button>
        </form>
        <div class="mt-4">
            <p>随机数列表：</p>
            <div id="result"></div>
        </div>
    </div>
    <script>
        function generate() {
            const num = parseInt(document.getElementById("num").value);
            const rangeMin = parseInt(document.getElementById("rangeMin").value);
            const rangeMax = parseInt(document.getElementById("rangeMax").value);

            if (isNaN(num) || isNaN(rangeMin) || isNaN(rangeMax)) {
                alert("请输入数字！");
                return;
            }

            if (rangeMin >= rangeMax) {
                alert("最小值必须比最大值小！");
                return;
            }

            let result = "";
            for (let i = 0; i < num; i++) {
                const randomNumber = Math.floor(Math.random() * (rangeMax - rangeMin + 1) + rangeMin);
                result += randomNumber;
                if (i < num - 1) {
                    result += ",";
                }
            }
            document.getElementById("result").innerHTML = result;
        }
    </script>
</body>
</html>